<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>AllowDynamicProperties 类</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.attribute.html">« Attribute</a></li>
      <li style="float: right;"><a href="class.return-type-will-change.html">ReturnTypeWillChange »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="reserved.attributes.html">预定义注解</a></li>
    <li>AllowDynamicProperties 类</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.allow-dynamic-properties" class="reference">
 <h1 class="title">AllowDynamicProperties 类</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 8 &gt;= 8.2.0)</p>

  <div class="section" id="allow-dynamic-properties.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    此注解用于标记 class，允许<a href="language.oop5.properties.html#language.oop5.properties.dynamic-properties" class="link">动态属性</a>。
   </p>
  </div>

  <div class="section" id="allow-dynamic-properties.synopsis">
   <h2 class="title">类摘要</h2>

   <div class="classsynopsis">
    <div class="ooclass">
     
    </div>

    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">final</span>
      <span class="modifier">class</span> <strong class="classname">AllowDynamicProperties</strong>
     </span>
     {</div>
   }</div>

  </div>

  <div class="section">
   <h2 class="title">范例</h2>
   <p class="para">
    从 PHP 8.2.0 起弃用动态属性，因此在不使用此注解标记类的情况下使用动态属性将发出弃用通知。
   </p>
   <div class="example" id="example-409">
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">DefaultBehaviour&nbsp;</span><span style="color: #007700">{&nbsp;}<br /><br /></span><span style="color: #FF8000">#[AllowDynamicProperties]<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">ClassAllowsDynamicProperties&nbsp;</span><span style="color: #007700">{&nbsp;}<br /><br /></span><span style="color: #0000BB">$o1&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DefaultBehaviour</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$o2&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">ClassAllowsDynamicProperties</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$o1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">nonExistingProp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$o2</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">nonExistingProp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程在 PHP 8.2 中的输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Deprecated: Creation of dynamic property DefaultBehaviour::$nonExistingProp is deprecated in file on line 10
</pre></div>
    </div>
   </div>
  </div>

  <div class="section" id="allow-dynamic-properties.seealso">
   <h2 class="title">参见</h2>
   <p class="para"><a href="language.attributes.html" class="link">注解概览</a></p>
  </div>

 </div>

</div>
</div></div></body></html>